package com.future.common.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.MDC;

import com.jfinal.handler.Handler;
import com.jfinal.kit.StrKit;

public class RequestIdHandler extends Handler {
	private static final String REQUESTID = "REQUESTID";
	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		String requestId = request.getHeader(REQUESTID);
		if(StrKit.isBlank(requestId)){
			requestId = StrKit.getRandomUUID();
		}
		MDC.put(REQUESTID, requestId);
		next.handle(target, request, response, isHandled);
	}

}
